package com.example.hello.client.TabPane;

import com.example.hello.BootstrapTabPane;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentContainerConnector;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapTabPane.class)
public class BootstrapTabPaneConnector extends AbstractComponentContainerConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapTabPane.class);
    }

    @Override
    public VBootstrapTabPane getWidget() {
        return (VBootstrapTabPane) super.getWidget();
    }

    @Override
    public BootstrapTabPaneState getState() {
        return (BootstrapTabPaneState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapTabPaneState state = getState();

        VBootstrapTabPane tabPane = getWidget();

        for (Connector connector : state.getWidgets()) {
            tabPane.add(((ComponentConnector) connector).getWidget());
        }
        tabPane.setActive(state.isActive());
        tabPane.setCreateTabLink(state.isCreateTabLink());
        tabPane.setHeading(state.getHeading());
        tabPane.setHref(state.getHref());
    }

    @Override
    public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {

    }

    @Override
    public void updateCaption(ComponentConnector connector) {

    }

}